package cn.gong.jizhang.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import cn.gong.jizhang.datacenter.data.RecordData;
import cn.gong.jizhang.enumparams.DbTaskType;
import cn.gong.jizhang.ui.base.BaseAct;
import cn.gong.jizhang.utils.StringUtils;

public class AddRecordAct extends BaseAct {

	private EditText moneyEt;
	private EditText markEt;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setLayout(R.layout.add_record);
		moneyEt = findEditTextById(R.id.add_record_et_money);
		markEt = findEditTextById(R.id.add_record_et_mark);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.add_record_ib_return:
			backToPrePage();
			break;
		case R.id.add_record_ib_ok:
			addRecord();
			break;
		}
	}

	private void addRecord() {
		String money = moneyEt.getText().toString();
		if (StringUtils.isEmpty(money)) {
			toast("请至少填上金额");
		}

		String mark = markEt.getText().toString();
		new RecordData().addRecord(Integer.parseInt(money),mark,this);
	}

	private void backToPrePage() {
		closeActForOld();
	}

	@Override
	protected void setClickListener() {
		setClick(R.id.add_record_ib_return);
		setClick(R.id.add_record_ib_ok);
	}

	@Override
	protected void clearDate() {
	}

	@Override
	protected void recoveryDate() {
	}

	@Override
	public void dbTaskFinish(DbTaskType tasktype, Object data) {
		switch (tasktype) {
		case DB_TS_ADD_RECORD:
			addRecordFinish(data);
			break;
		}
	}

	private void addRecordFinish(Object data) {
		boolean isSuccess=(Boolean) data;
		if(isSuccess){
			toast("添加成功");
		}else{
			toast("添加失败");
		}
	}

}
